﻿using ZYCommon;
using System;
using System.Drawing;
using System.Xml;

namespace TextEditor
{
    

    public class ImageRectAction : ImageEditAction
    {
        public Color BorderColor = Color.Black;
        public int BorderWidth = 1;

        public override bool Execute(Graphics g, Rectangle ClipRect)
        {
            using (Pen pen = new Pen(this.BorderColor, (float) this.BorderWidth))
            {
                g.DrawRectangle(pen, base.myBounds);
            }
            return true;
        }

        public override bool FromXML(XmlElement myElement)
        {
            base.BoundsFromXML(myElement);
            this.BorderColor = StringCommon.ColorFromHtml(myElement.GetAttribute("color"), Color.Black);
            this.BorderWidth = Convert.ToInt32(myElement.GetAttribute("borderwidth"));
            return true;
        }

        public override bool ToXML(XmlElement myElement)
        {
            base.BoundsToXML(myElement);
            myElement.SetAttribute("color", StringCommon.ColorToHtml(this.BorderColor));
            myElement.SetAttribute("borderwidth", this.BorderWidth.ToString());
            return true;
        }

        public override string ActionName
        {
            get
            {
                return "rect";
            }
        }
    }
}

